package com.xique.park.controller.web;

import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.park.bean.request.app.ParkUserListRequest;
import com.xique.park.bean.request.web.car.ParkUserSaveRequest;
import com.xique.park.bean.request.web.user.AddUserRequest;
import com.xique.park.bean.request.web.user.SelectParkUserRequest;
import com.xique.park.bean.request.web.user.UpdateUserRequest;
import com.xique.park.service.biz.service.IParkUserBizService;
import com.xique.park.service.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 车主管理controller
 *
 * @author xique
 */
@RestController
@RequestMapping("/web/user")
public class WebParkUserController extends BaseController {

    @Autowired
    private IParkUserBizService parkUserBizService;

    @Autowired
    private IUserService userService;


    /**
     * 查询用户列表
     */
    @PostMapping("/list")
    public AjaxResult list(@Validated @RequestBody ParkUserListRequest request) {
        return parkUserBizService.getWebParkUserList(request);
    }

    /**
     * 保存车主信息（添加或者更新）
     */
    @Log(title = "用户信息(车主)", businessType = BusinessType.UPDATE)
    @PostMapping("/save")
    public AjaxResult addParkCar(@Validated @RequestBody ParkUserSaveRequest request) {
        return parkUserBizService.saveParkUser(request);
    }

    /**
     * 查询用户列表
     */
    @GetMapping("/condition/list")
    public AjaxResult conditionList(SelectParkUserRequest request) {
        return parkUserBizService.conditionList(request);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/delete")
    public AjaxResult delete(String ids) {
        if (StringUtils.isEmpty(ids)){
            return AjaxResult.error("请选择需要删除的用户！");
        }
        return parkUserBizService.delete(ids);
    }

    /**
     * 新增用户
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated AddUserRequest request) {
        return parkUserBizService.add(request);
    }


    /**
     * 修改用户
     */
    @PutMapping("/update")
    public AjaxResult update(@Validated @RequestBody UpdateUserRequest request) {
        return parkUserBizService.update(request);
    }
}
